#include "xmppcore/parsingutils.h"

#include <QtCore/QXmlStreamReader>

namespace yoohoo_xmppcore {

bool ParsingUtils::readXmlLang(QList<ParsingAttribute> attributes, QString& xmlLang) {
	if (attributes.size() == 0)
		return true;

	if (attributes.size() != 1)
		return false;

	foreach (ParsingAttribute attribute, attributes) {
		if ("xml" != attribute.prefix() || "lang" != attribute.localName()) {
			return false;
		} else {
			xmlLang = attribute.value();
		}
	}

	return true;
}

void ParsingUtils::appendText(QXmlStreamReader* reader, QString& text) {
	QString textFragment = reader->text().toString().trimmed();
	// if the characters are white space, ignore them
	if (textFragment.isEmpty()) {
		return;
	}

	text.append(textFragment);
}

}
